const DATA = (() => {
    let data = localStorage.getItem('guysIdList');
    if (data) {
        data = JSON.parse(data);
        data.forEach(guy => {
            guy.needInsurance = false;
        });
    }
    else {
        history.back();
    }
    return data;
})();

const vm = new Vue({
    el: '#main',
    data: {
        list: DATA,
        num: '0',
        total: '0.0',
        nightNum: JSON.parse(localStorage.getItem('DATA_book_room')).infoDate.nightNum,
    },
    methods: {
        selectGuy,
        finish,
    },
});

function apiready() {
    fxj.fixLayout();
}

function selectGuy(guy) {
    guy.needInsurance = !guy.needInsurance;
    let num = 0;
    vm.list.forEach(guy => {
        if (guy.needInsurance) {
            num++;
        }
    });
    vm.num = num;
    if (num > 0) {
        num--;
    }
    vm.total = num * 0.5 * vm.nightNum;
}

function finish() {
    localStorage.setItem('guysIdList', JSON.stringify(vm.list));
    history.back();
}